package resource

import (
	"supervideo/app/models"
	"supervideo/app/models/platform"
	"supervideo/app/models/video"
	"supervideo/pkg/database"
)

type Resource struct {
	models.BaseModel

	Title      string `json:"title"`
	Sort       int8   `json:"sort,omitempty"`
	Status     int8   `json:"status,omitempty"`
	platformId uint64
	videoId    uint64
	AsName     string `json:"asname"`
	Remark     string `json:"remark"`

	Description string `json:"description"`

	Platform platform.Platform `json:"platform"`
	Video    video.Video       `json:"video"`

	models.CommonTimestampsField
}

func (resource *Resource) Create() {
	database.DB.Create(&resource)
}

func (resource *Resource) Save() (rowAffected int64) {
	result := database.DB.Save(&resource)
	return result.RowsAffected
}

func (resource *Resource) Delete() (rowAffected int64) {
	result := database.DB.Delete(&resource)
	return result.RowsAffected
}
